package team.sun.sss.dao.extra;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;
import team.sun.sss.pojo.extra.ExtraStaff;
import team.sun.sss.pojo.extra.ExtraWork;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface ExtraDao {

    //两表联合
    @Select("select * from extra_staff where extra_time=#{extraTime}")
    ExtraStaff selectExtraStaff(Date extraTime);

    @Select("select * from extra_work")
    @Results(
            id = "selectExtraWork",
            value = {
                    @Result(property = "extraId",column = "extra_id",id = true),
                    @Result(property = "extraTime",column = "extra_time"),
                    @Result(property = "extraDetail",column = "extra_detail"),
                    @Result(property = "extraPublisher",column = "extra_publisher"),
                    @Result(property = "extraStaffList",column = "extra_time",many=@Many(select="selectExtraStaff",fetchType= FetchType.LAZY)),
            }
    )
    List<ExtraWork> selectAll();

    //值班表添加数据
    @Insert("insert into extra_work(extra_time,extra_publisher) values(#{extraTime},#{extraPublisher})")
    int insertExtraWork(ExtraWork extraWork);

    //值班表添加数据
    @Insert("insert into extra_staff(extra_time,sta_name) values(#{extraTime},#{staName})")
    int insertExtraStaff(ExtraStaff ExtraStaff);

    //值班人员表根据姓名查询
    @Select("select * from extra_staff where sta_name=#{staName} and extra_time> now() order by extra_time")
    List<ExtraStaff> selectByName(String staName);
    //值班人员表根据日期查询
    @Select("select * from extra_staff where extra_time=#{extraTime}")
    List<ExtraStaff> selectByDate(java.sql.Date extraTime);

    //值班表获取所有时间
    @Select("select * from extra_work where extra_time> now() order by extra_time")
    List<ExtraWork> selectAllDate();
}
